//
//  ThreeViewController.m
//  HXBaseProjectDemo
//
//  Created by YaSha_Tom on 2018/2/5.
//  Copyright © 2018年 亚厦装饰股份有限公司. All rights reserved.
//

#import "ThreeViewController.h"
#import "CommonApplicationModel.h"

@interface ThreeViewController ()

@end

@implementation ThreeViewController

- (void)initSubviews {
    [super initSubviews];
    self.title = @"工作台";
    [self getDatasourceArray];
}
- (void)getDatasourceArray {
    [self.dataSourceArray addObjectsFromArray:[CommonDataManager getApplicationsData:@[@{@"id": @"0",
                                                                                     @"name": @"待办",
                                                                                     @"imageName": @"待办",
                                                                                     @"modelName": @"flowCenter",
                                                                                     @"className": @"YSFlowPageController"},
                                                                                   @{@"id": @"1",
                                                                                     @"name": @"日程",
                                                                                     @"imageName": @"日程",
                                                                                     @"modelName": @"",
                                                                                     @"className": @"YSCalendarViewController"},
                                                                                   @{@"id": @"2",
                                                                                     @"name": @"新闻公告",
                                                                                     @"imageName": @"公文",
                                                                                     @"modelName": @"newsBulletin",
                                                                                     @"className": @"YSNewsPageController"},
                                                                                   @{@"id": @"3",
                                                                                     @"name": @"HR服务",
                                                                                     @"imageName": @"EHR",
                                                                                     @"modelName": @"",
                                                                                     @"className": @"YSHRFunctionViewController"},
                                                                                   @{@"id": @"4",
                                                                                     @"name": @"固定资产",
                                                                                     @"imageName": @"固定资产",
                                                                                     @"modelName": @"",
                                                                                     @"className": @"YSAssetsFunctionViewController"},
                                                                                   @{@"id": @"5",
                                                                                     @"name": @"自助报障",
                                                                                     @"imageName": @"IT运维",
                                                                                     @"modelName": @"",
                                                                                     @"className": @"YSRepairViewController"},
                                                                                   @{@"id": @"6",
                                                                                     @"name": @"项目管理",
                                                                                     @"imageName": @"ic_app_pm_zhuang",
                                                                                     @"modelName": @"",
                                                                                     @"className": @"YSPMSZSFunctionViewController"},
                                                                                   @{@"id": @"7",
                                                                                     @"name": @"项目管理",
                                                                                     @"imageName": @"ic_app_pm_mu",
                                                                                     @"modelName": @"",
                                                                                     @"className": @"YSPMSMQFunctionViewController"},
                                                                                   @{@"id": @"8",
                                                                                     @"name": @"供应链",
                                                                                     @"imageName": @"供应链",
                                                                                     @"modelName": @"",
                                                                                     @"className": @"YSSupplyFunctionViewController"},
                                                                                                                                                                      @{@"id": @"9",
                                                                                                                                                                        @"name": @"EMS",
                                                                                                                                                                        @"imageName": @"EMS",
                                                                                                                                                                        @"modelName": @"",
                                                                                                                                                                        @"className": @"YSEMSFunctionViewController"},
                                                                                   @{@"id": @"10",
                                                                                     @"name": @"一卡通充值",
                                                                                     @"imageName": @"饭卡充值",
                                                                                     @"modelName": @"",
                                                                                     @"className": @"YSRechargeViewController"},
                                                                                   @{@"id": @"11",
                                                                                     @"name": @"",
                                                                                     @"imageName": @"添加",
                                                                                     @"modelName": @"",
                                                                                     @"className": @""}
                                                                                   ]]];
    NSLog(@"==========%@",self.dataSourceArray);
    [self.collectionView reloadData];
//    [self doNetworking];
}

//- (void)doNetworking {
//    NSString *urlString = [NSString stringWithFormat:@"%@%@", YSDomain, getCornerMarkApi];
//    [YSNetManager ys_request_GETWithUrlString:urlString isNeedCache:NO parameters:nil successBlock:^(id response) {
//        DLog(@"========%@",response);
//        dispatch_async(dispatch_get_global_queue(0, 0), ^{
//            if ([response[@"code"] integerValue] == 1) {
//                NSArray *datasourceAarray = [YSDataManager getApplicationsWithBadgeWithDatasource:self.dataSourceArray andResponse:response];
//                [self.dataSourceArray removeAllObjects];
//                [self.dataSourceArray addObjectsFromArray:datasourceAarray];
//                dispatch_async(dispatch_get_main_queue(), ^{
//                    NSString *badgeValue = [NSString stringWithFormat:@"%@", response[@"data"][@"total"]];
//                    NSInteger totalUnreadCount = [[RCIMClient sharedRCIMClient] getTotalUnreadCount];
//                    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:([badgeValue integerValue] + totalUnreadCount)];
//                    //                    [YSUtility setApplicationIconBadgeNumber];
//                    //                    [self.rt_navigationController.tabBarItem setBadgeValue:badgeValue];
//                    [self.collectionView reloadData];
//                });
//            }
//        });
//    } failureBlock:^(NSError *error) {
//        DLog(@"error:%@", error);
//        [self.collectionView reloadData];
//    } progress:nil];
//}

#pragma mark - UICollectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    CommonApplicationModel *model = self.dataSourceArray[indexPath.row];
    Class someClass = NSClassFromString(model.className);
    if (someClass) {
        UIViewController *viewController = [[someClass alloc] init];
        
        [self.navigationController pushViewController:viewController animated:YES];
    } else {
        [QMUITips showInfo:@"敬请期待！" inView:self.view hideAfterDelay:1];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
